package com.atguigu.cloud.controller;


import cn.hutool.core.date.DateUtil;
import com.atguigu.cloud.apis.PayFeignApi;
import com.atguigu.cloud.entities.PayDTO;
import com.atguigu.cloud.resp.ResultData;
import com.atguigu.cloud.resp.ReturnCodeEnum;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

/**
 * @ClassName OrderController
 * @Author link
 * @Date: 2024/10/31 下午2:45
 * @Version v1.0
 * @Description:
 */
@RestController
@Slf4j
public class OrderController {
    @Resource
    private PayFeignApi payFeignApi;

    @GetMapping("/consumer/pay/add")
    public ResultData addOrder(PayDTO payDTO){
        return payFeignApi.addPay(payDTO);
    }
    @GetMapping("/consumer/pay/get/{id}")
    public ResultData getPayInfo(@PathVariable("id") Integer id){
        return payFeignApi.getPayById(id);
    }
    @GetMapping("/consumer/pay/update")
    public ResultData updatePayInfo(PayDTO payDTO){
        return payFeignApi.updatePay(payDTO);
    }
    @GetMapping("/consumer/pay/del/{id}")
    public ResultData delPayInfo(@PathVariable("id") Integer id){
        return payFeignApi.deletePay(id);
    }
    @GetMapping("/consumer/pay/getall")
    public ResultData getPayAllInfo(){
        System.out.println("-----------支付微服务远程调用，查询全部订单支付流水信息");
        ResultData resultData = null;

        try{
            System.out.println("-----调用开始："+ DateUtil.now());
            resultData = payFeignApi.getPayList();

        }catch (Exception e){
            e.printStackTrace();
            System.out.println("-----调用结束："+ DateUtil.now());
            return ResultData.fail(ReturnCodeEnum.RC500.getCode(), e.getMessage());
        }

        return resultData;
    }

    @GetMapping(value = "/consumer/pay/get/info")
    private String getInfoByConsul()
    {
        return payFeignApi.getInfoByConsul();
    }

}
